package problem;

/**
 * @author RunningShrimp
 * @date 2021/6/10  15:35
 * @see <a href="https://leetcode-cn.com/problems/remove-element/">27. 移除元素</a>
 */
public class RemoveElement {
    public int removeElement(int[] nums, int val) {
        int flag = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != val) {
                if (flag != i) {
                    int temp = nums[i];
                    nums[i] = nums[flag];
                    nums[flag] = temp;
                }
                flag++;

            }
        }
        return flag;
    }
}
